/**
 * 
 */
package br.com.ufrn.aipetro.ga.controller.device;

import java.util.List;

import br.com.ufrn.aipetro.ga.controller.interfaces.AbstractController;
import br.com.ufrn.aipetro.ga.domain.entity.device.Critical;
import br.com.ufrn.aipetro.ga.persist.interfaces.DaoFactory;

/**
 * @author Andre
 * @author Lucas
 */
public class CriticalController extends AbstractController<Critical> {
	
	DaoFactory daoFactory;
	
	public CriticalController(DaoFactory factory) {
		this.daoFactory = factory;
		setModel(new Critical());
	}
	
	public void changeName(String name) {
		getModel().setName(name);
	}
	
	public void persistDelete(Critical critical) {
		daoFactory.beginTransaction();
		daoFactory.createCriticalDao().delete(critical);
		daoFactory.commitTransaction();
	}
	
	public void persistInsert() {
		daoFactory.beginTransaction();
		daoFactory.createCriticalDao().insert(getModel());
		daoFactory.commitTransaction();
	}
	
	public void persistUpdate() {
		daoFactory.beginTransaction();
		daoFactory.createCriticalDao().update(getModel());
		daoFactory.commitTransaction();
	}
	
	public List<Critical> persistSearchByExample(Critical example) {
		daoFactory.beginTransaction();
		List<Critical> criticalList = daoFactory.createCriticalDao().searchByExample(example);
		daoFactory.commitTransaction();
		return criticalList;
	}

}
